/**
 * 
 */
package com.jie.eclipse.pan.swtitem.table;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.editors.utils.PanImageHelper;

/**
 * @author yanjie
 *
 */
public class PllTableLabelProvider implements ITableLabelProvider ,ITableColorProvider {
	private PTableViewer tv = null;
	private Color color1 = null;
	private Color color2 = null;
	/**
	 * 
	 */
	public PllTableLabelProvider(PTableViewer tv) {
		color1=new Color(null,Integer.parseInt("FF",16),Integer.parseInt("A0",16),Integer.parseInt("A0",16));
		color2=new Color(null,Integer.parseInt("CC",16),Integer.parseInt("EE",16),Integer.parseInt("DD",16));
		this.tv = tv;
		
	}
	
	public void addListener(ILabelProviderListener arg0) {
		
	}

	public void dispose() {
		
	}

	public boolean isLabelProperty(Object arg0, String arg1) {
		return false;
	}

	public void removeListener(ILabelProviderListener arg0) {
		
	}

	public Image getColumnImage(Object element, int col) {
		if(element instanceof BaseDataEntity){
			BaseDataEntity row = (BaseDataEntity)element;
			String colname = this.tv.getPTable().getColumnName(col);
			if(!row.isNullOrEmpty(colname+"_img")){
				return PanImageHelper.getInstance().getImage(row.gpsv(colname+"_img"));
			}else if(row.gpov(colname+"_img") instanceof Image){
				return (Image)row.gpov(colname+"_img");
			}
		}
		return null;
	}
	
	public String getColumnText(Object element, int col) {
		if(element instanceof BaseDataEntity){
			return ((BaseDataEntity)element).gpsv(this.tv.getPTable().getColumnName(col));
		}
		return "";
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableColorProvider#getBackground(java.lang.Object, int)
	 */
	public Color getBackground(Object element, int col) {
		if(element instanceof BaseDataEntity){
			BaseDataEntity row= (BaseDataEntity)element;
			if("0".equals(row.gpsv("status_code"))){
				return color1;
			}else{
				return color2;
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableColorProvider#getForeground(java.lang.Object, int)
	 */
	public Color getForeground(Object element, int col) {
		return null;
	}
	
}
